<template>
  <div>
    <div style="display: flex;justify-content: center;margin-top: 80px">
      <el-card style="width: 80%;margin: 10px">
        <div style="display: flex;align-items: center;justify-content: center">
          <div style="width: 80%;margin: 10px">
            <div style="height: 50px;font-size: 25px">我的优惠券</div>
            <div style="margin-bottom: 10px"></div>
            <el-table ref="couponData" :data="couponData" stripe
                      :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}">
              <el-table-column prop="id" label="id"></el-table-column>
              <el-table-column prop="name" label="优惠券名称 "></el-table-column>
              <el-table-column prop="discount" label="优惠券金额 "></el-table-column>
              <el-table-column prop="status" label="状态"></el-table-column>
            </el-table>
            <div style="margin: 10px 0">
              <el-pagination
                  @current-change="handleCurrentChange2"
                  :current-page="pageNum2"
                  :page-sizes="[100, 200, 300, 400]"
                  :page-size="pageSize2"
                  layout="total,  prev, pager, next"
                  :total="total2">
              </el-pagination>
            </div>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "myCoupon",
  data() {
    return {
      couponData: [],
      pageNum2: 1,   //当前页码
      pageSize2: 5,    //每页数量
      total2: 0,
      user: JSON.parse(localStorage.getItem('user') || '{}'),
    }
  },
  created() {
    this.loadCoupon();
  },
  methods: {
    handleCurrentChange2(pageNum2) {//下一页
      this.loadCoupon(pageNum2)
    },
    loadCoupon(pageNum2) {
      if (pageNum2) this.pageNum2 = pageNum2
      this.$request.post('/coupon_entity_list/', {
        "username": this.user.username,
        "page_size": this.pageSize2,
        "page_id": this.pageNum2,
      }).then(res => {
        if (res.code === '200') {
          this.couponData = res.data.coupon_list
          this.total2 = res.data.item_amount
          console.log("优惠券数据xxx", res.data.coupon_list)
        } else if (res.code === '501') {
          console.log("aaaaa")
        } else {
          console.log("bbbbb")
          this.$message.error(res.msg)
        }
      })
    },
  }
}
</script>

<style scoped>

</style>